package com.sdcx.agrobank.util;


import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.sdcx.agrobank.R;

import java.io.File;

import jp.wasabeef.glide.transformations.BlurTransformation;

/**
 * 暂时没有占位图
 */

public class GlideUtil {

    //加载圆形头像
    public static void displayAvatar(Context context, String url, ImageView view) {
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .circleCrop()//设置圆形
//                .placeholder(com.hyphenate.easeui.R.drawable.ease_group_icon)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
//8        Glide.with(context).load(url).placeholder(R.mipmap.haveyou_logo).apply(options).into(view);


    }

    //加载圆形头像
    public static void displayAvatar(Context context, int resourceId, ImageView view) {
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .circleCrop()//设置圆形
//                .placeholder(com.hyphenate.easeui.R.drawable.ease_group_icon)
//                .error()
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load(resourceId).apply(options).into(view);
    }

    //加载网络图片
    public static void display(Context context, String url, ImageView view) {
        RequestOptions options = new RequestOptions()
//                .centerCrop()
//                .placeholder(com.hyphenate.easeui.R.drawable.ease_group_icon)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
//                .bitmapTransform(new CropCircleTransformation(context));
        Glide.with(context).load(url).apply(options).into(view);
    }

    //加载网络图片 加高斯模糊
    public static void displayG(Context context, String url, ImageView view) {
        RequestOptions options = RequestOptions
                .bitmapTransform(new BlurTransformation(14, 3));
        Glide.with(context).load(url).apply(options).into(view);
    }

    //加载网络图片 加圆角图片
    public static void displayR(Context context, String url,int radio, ImageView view) {
        RequestOptions options = new RequestOptions()
                .centerCrop()//设置圆形
//                .placeholder(R.color.white)
//                .error(R.color.white)
                .transform(new GlideRoundTransform(context, radio));
        Glide.with(context).load(url).apply(options).into(view);
    }

    public static void displayR(Context context, int url, ImageView view) {
        RequestOptions options = new RequestOptions()
                .centerCrop()//设置圆形
//                .placeholder(R.color.white)
//                .error(R.color.white)
                .transform(new GlideRoundTransform(context, 8));
        Glide.with(context).load(url).apply(options).into(view);
    }

    public static void displayR(Context context, String url, ImageView view, int radius) {
        RequestOptions options = new RequestOptions()
                .centerCrop()//设置圆形
//                .placeholder(R.color.white)
//                .error(R.color.white)
                .transform(new GlideRoundTransform(context, radius));
        Glide.with(context).load(url).apply(options).into(view);
    }

    public static void displayR(Context context, int url, ImageView view, int radius) {
        RequestOptions options = new RequestOptions()
                .centerCrop()//设置圆形
//                .placeholder(R.color.white)
//                .error(R.color.white)
                .transform(new GlideRoundTransform(context, radius));
        Glide.with(context).load(url).apply(options).into(view);
    }

    public static int displayRe(Context context, int url, ImageView view, int radius) {
        RequestOptions options = new RequestOptions()
                .centerCrop()//设置圆形
//                .placeholder(R.color.white)
//                .error(R.color.white)
                .transform(new GlideRoundTransform(context, radius));
        Glide.with(context).load(url).apply(options).into(view);
        return 1;
    }

    //从资源中加载
    public static void display(Context context, int resourceId, ImageView view) {
        Glide.with(context).load(resourceId).into(view);
    }

    //从文件中加载
    public static void display(Context context, File file, ImageView view) {
        Glide.with(context).load(file).into(view);
    }

}
